<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    *{
        margin: 0;
        padding: 0;
    }
    .box{
        margin:  100px auto;
        width: 300px;
        height: 300px;
        border: 1px solid red;
    }
</style>
<body>
    <div class="box">
        <button>注册</button>
    </div>
</body>
<script>
    var box = document.querySelector('.box')
    var but = document.querySelector('button')

    box.onclick = function(event){
        event = event || window.event 
        console.log('box');
        //阻止冒泡
        if(event.stopPropagation){
            event.stopPropagation()
        }else{
            //ie
            event.cancelBubble = true
        }
    }
    but.onclick = function(event){
        event = event || window.event
        console.log('button')
        //阻止冒泡
        if(event.stopPropagation){
            event.stopPropagation()
        }else{
            //ie
            event.cancelBubble = true
        }
    }
    window.onclick = function(){
        console.log('window')
    }
</script>
</html>